﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BEGDC.CC.Web.UserControls;
using BEGDC.CC.BL.CCFlow.CR;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.SystemManagement
{
	/// <summary>
	/// Summary description for Vehicles.
	/// </summary>
	public class Vehicles : System.Web.UI.Page
	{
		#region VARIABLES
		protected System.Web.UI.WebControls.DropDownList Dp_VehicleType;
		protected System.Web.UI.WebControls.DataGrid DG_Vehicle;
		protected System.Web.UI.HtmlControls.HtmlImage VehiclePaneImg;
		#endregion
	
		private void Page_Load(object sender, System.EventArgs e)
		{
				InitForm();
		}

		#region InitForm
		private void InitForm()
		{
			//INIT VEHICLE TABLE
			string VehicleType = this.Dp_VehicleType.SelectedValue;
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			IList VehicleList = CRService.GetVehicleTypes(VehicleType);
			this.DG_Vehicle.DataSource = VehicleList;
			this.DG_Vehicle.DataBind();
		}
		#endregion

		#region Vehicle List Data Bound
		private void VehicleListDateBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				System.Web.UI.WebControls.ImageButton Btn_Edit = (System.Web.UI.WebControls.ImageButton) e.Item.Cells[4].FindControl("Btn_Vehicle_Edit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenVehiclePane("+ItemId+");");
			}
		}
		#endregion

		private void VehicleTypeSelectChange(object sender, System.EventArgs e)
		{
			string VehicleType = this.Dp_VehicleType.SelectedValue;
			ICR CRService = AppContainer.Instance[ServiceConst.CRService] as ICR;
			IList QuestionList = CRService.GetVehicleTypes(VehicleType);
			this.DG_Vehicle.DataSource = QuestionList;
			this.DG_Vehicle.DataBind();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Dp_VehicleType.SelectedIndexChanged += new System.EventHandler(this.VehicleTypeSelectChange);
			this.DG_Vehicle.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.VehicleListDateBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
